﻿using System.Collections.Generic;
using UscSunShine.Models;


namespace UscSunShine.ViewModels.ExtensionMethod
{
    public static class RequestExtension
    {
        /// <summary>
        /// 将Request转换为ViewModel
        /// </summary>
        /// <param name="model">申请</param>
        /// <returns></returns>
        public static RequestViewModel ToView(this Request model)
        {
            var view = new RequestViewModel
            {
                ID = model.ID,
                AcceptDate = model.AcceptDate,
                AcceptNumber = model.AcceptNumber,
                ContactPhone = model.ContactPhone,
                Content = model.Content,
                DepartmentID = model.DepartmentID,
                Department = model.Department,
                DepartmentName = model.Department.Name,
                Email = model.Email,
                ExpectResolveDate = model.ExpectResolveDate,
                ProcessDate = model.ProcessDate,
                ProcessStatus = model.ProcessStatus,
                ProcessStatusName = EnumExtension.GetEnumCustomDescription(model.ProcessStatus),
                RequestCategory = model.RequestCategory,
                RequestCategoryName = EnumExtension.GetEnumCustomDescription(model.RequestCategory),
                RespondContent = model.RespondContent,
                Title = model.Title,
                Username = model.Username,
                ViewTimes = model.ViewTimes
            };

            return view;
        }

        /// <summary>
        /// 将Request列表转换为ViewModel列表
        /// </summary>
        /// <param name="models">申请列表</param>
        /// <returns></returns>
        public static IEnumerable<RequestViewModel> ToViews(this IEnumerable<Request> models)
        {
            var views = new List<RequestViewModel>();
            foreach (var item in models)
            {
                var view = item.ToView();
                views.Add(view);
            }
            return views;
        }


        /// <summary>
        /// RequestViewModel转换为Request
        /// </summary>
        /// <param name="view">公告ViewModel</param>
        /// <returns></returns>
        public static Request ToModel(this RequestViewModel view)
        {
            var model = new Request
            {
                ID = view.ID,
                AcceptDate = view.AcceptDate,
                AcceptNumber = view.AcceptNumber,
                ContactPhone = view.ContactPhone,
                Content = view.Content,
                DepartmentID = view.DepartmentID,
                Department = view.Department,
                Email = view.Email,
                ExpectResolveDate = view.ExpectResolveDate,
                ProcessDate = view.ProcessDate,
                ProcessStatus = view.ProcessStatus,
                RequestCategory = view.RequestCategory,
                RespondContent = view.RespondContent,
                Title = view.Title,
                Username = view.Username,
                ViewTimes = view.ViewTimes
            };
            return model;
        }

        /// <summary>
        /// RequestViewModel列表转换为Request列表
        /// </summary>
        /// <param name="views">RequestViewModel列表</param>
        /// <returns></returns>
        public static IEnumerable<Request> ToModels(this IEnumerable<RequestViewModel> views)
        {
            var models = new List<Request>();
            foreach (var item in views)
            {
                var model = item.ToModel();
                models.Add(model);
            }
            return models;
        }
    }
}
